package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseBaseApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseBaseVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseBaseController implements CourseBaseApi {

    @Autowired
    private CourseBaseService  courseBaseService;


    @PostMapping("course/list")
    public PageVO findCourseBases(PageRequestParams pageRequestParams, @RequestBody QueryCourseModel model) {
        //获取token 中储存的 机构ID
        Long companyId = SecurityUtil.getCompanyId();
        PageVO<CourseBaseDTO> courseBase = courseBaseService.queryCourseBase(pageRequestParams,model,companyId);
        return courseBase;
    }

    @PostMapping("course")
    public CourseBaseDTO saveCourse(@RequestBody CourseBaseVO baseVO) {
        Long companyId = SecurityUtil.getCompanyId();
        return courseBaseService.getCourse(baseVO,companyId);
    }

    @GetMapping("course/{courseBaseId}")
    public CourseBaseDTO findCourseBaseById(@PathVariable("courseBaseId") Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();

        return courseBaseService.getCourseBaser(courseBaseId,companyId);
    }

    @PutMapping("course")
    public CourseBaseDTO modifyCourseBase(@RequestBody CourseBaseVO courseBaseVO) {
        Long companyId = SecurityUtil.getCompanyId();
        return  courseBaseService.modifyCourseBaser(courseBaseVO,companyId);
    }
    @DeleteMapping("course/{coursebaseId}")
    public Boolean removeCourseBase(@PathVariable Long coursebaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        return courseBaseService.removeCourseBase(coursebaseId,companyId);
    }

    @GetMapping("/course/commit/{courseBaseId}")
    public void modifyCourse(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        courseBaseService.modifyCourseBaseById(courseBaseId,companyId);
    }

    @PostMapping("m/courseReview/approve")
    public void modifyMCourse(@RequestBody Map<String, String> map) {
        Long courseBaseId =  Long.valueOf(map.get("courseBaseId"));//课程ID
        String auditMind = map.get("auditMind"); //审核意见
        String auditStatus = map.get("auditStatus");//审核状态
        courseBaseService.modifyMCourseBaseById(courseBaseId,auditMind,auditStatus);
    }

    @PostMapping("m/course/list")
    public PageVO<CourseBaseDTO> queryCourseM(PageRequestParams params, @RequestBody QueryCourseModel model) {
        PageVO<CourseBaseDTO> courseBaseDTOS = courseBaseService.queryCourseBase(params, model, null);
        return courseBaseDTOS;
    }


    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryCourseTeacher(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        List<CourseTeacherDTO> courseTeacherDTOS = courseBaseService.queryCourseTeachers(courseBaseId, companyId);
        return courseTeacherDTOS;
    }




}
